package com.chis.kafka;

import org.apache.kafka.clients.producer.Callback;
import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.Producer;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.apache.kafka.clients.producer.RecordMetadata;

import java.util.Properties;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

/**
 * 
 * @Description 
 * @Company zwx
 * @author wlj
 * @version 2019年06月11日
 */
public class TestKafkaPro {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
//        String ha = args[0];
//        String jks = args[1];
        Properties props = new Properties();
//        props.put("bootstrap.servers", "10.88.88.172:19091");
//        props.put("bootstrap.servers", "zwxwx.chinaymt.cn:31193");
//        props.put("bootstrap.servers", ha);
        props.put("bootstrap.servers", "10.88.88.107:9092,10.88.88.106:9092,10.88.88.105:9092");
        props.put("acks", "all");
        props.put("retries", 0);
        props.put("batch.size", 163840);
        props.put("linger", 300);
        props.put("buffer.memory", 33554432);
        props.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
        props.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");
        //ssl
//        props.put("security.protocol", "SSL");
//        props.put("ssl.truststore.location", "C:\\Users\\wlj\\Desktop\\client.truststore.jks");
//        props.put("ssl.truststore.location", jks);
//        props.put("ssl.truststore.password", "chiscdc");
//        props.put("ssl.endpoint.identification.algorithm", "");
//        props.put("request.timeout.ms","2000");
        props.put("session.timeout.ms","2000");

        Producer<String, String> producer = new KafkaProducer<>(props);
        for(int i =0 ; i < 100 ;i++){
            producer.send(new ProducerRecord<String, String>("wlj2", "wlj"+i));
        }
        
//        Future<RecordMetadata> future = producer.send(new ProducerRecord<String, String>("wlj2", valu);
//        RecordMetadata recordMetadata=future.get();
//        System.out.format("分区: %d 偏移量: %d\n", recordMetadata.partition(),recordMetadata.offset());
        producer.close();
        System.out.println(1);
    }

}
